<?php
namespace app\common\behavior;
use think\Config;
use think\Request;
class Init{
    public function run(&$params){
		if(empty(config('site.site_close')) && ENTRANCE=='index' && empty(session('member_auth'))){
		   header("Content-Type:text/html; charset=utf-8");
		   $close=config('site.site_close_tip');
           echo $close;
		   exit();
		}		
        //根据配置和参数来设置模版。
        $default_view_path = ROOT_PATH.'tpl'.DS.'home'.DS;//获取设置的模版路径
		$request = Request::instance();
		$domain=$request->server('HTTP_HOST');
		$mobile=config('site.site_wapurl');
        if ($default_view_path != ''){
			if($domain==str_replace(array('http://','https://'),'',$mobile)){
				$theme_path = config('site.mobile_theme'); //设置主题默认路径为手机端
			}else{
			    $theme_path = config('site.default_theme'); //设置主题默认路径为电脑端	
			}		
            config('template.view_path',$default_view_path.$theme_path.DS);//设置模版路径  	
        }
		config('template.strip_space',config('system.system_strip_space'));
        config('user',F('_user/config'));		
        //根据配置和来自动切换主题
		$config['site']=config('site');
		$config['system']=config('system');
		$config['upload']=config('upload');
		$config['video']=config('video');
		$config['cache']=config('cache');
		$config['setting']=config('setting');
		$config['html']=F('_html/config');
		$config['rewrite']=F('_rewrite/config');
		$config['play']=F('_play/play');
		$config['model']=config('model');
		$config['user']=config('user');
		$GLOBALS['config'] = $config;		
    }	
}